package com.yupi.yoj.model.enums;

import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 题目提交编程语言枚举
 *
 * @author <a href="https://github.com/liyupi">程序员鱼皮</a>
 * @from <a href="https://yupi.icu">编程导航知识星球</a>
 */
public enum QuestionSubmitLanguageEnum {
        JAVA("java", "java"),
        CPLUSPLUS("c++", "c++"),
        GOLANG("golang", "golang");

        private final String text;

        private final String value;

        QuestionSubmitLanguageEnum(String text, String value) {
            this.text = text;
            this.value = value;
        }

        /**
         * 获取值列表
         *
         * @return
         */
        public static List<String> getValues() {
            return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
        }

        /**
         * 根据 value 获取枚举
         *
         * @param value
         * @return
         */
        public static QuestionSubmitLanguageEnum getEnumByValue(String value) {
            if (ObjectUtils.isEmpty(value)) {
                return null;
            }
            for (QuestionSubmitLanguageEnum anEnum : QuestionSubmitLanguageEnum.values()) {
                if (anEnum.value.equals(value)) {
                    return anEnum;
                }
            }
            return null;
        }

        public String getValue() {
            return value;
        }

        public String getText() {
            return text;
        }
    }


